import factory, { type mxGraphOptions } from "mxgraph";

const factoryOption: mxGraphOptions = {
    mxBasePath: "/libs/mxgraph-base",
    mxDefaultLanguage: "en",
    mxImageBasePath: "/libs/mxgraph-base/images",
    mxLanguage: "en",
    mxLoadResources: false,
    mxLoadStylesheets: true,
};

(window as any)["mxBasePath"] = factoryOption.mxBasePath;
(window as any)["mxDefaultLanguage"] = factoryOption.mxDefaultLanguage;
(window as any)["mxImageBasePath"] = factoryOption.mxImageBasePath;
(window as any)["mxLoadResources"] = factoryOption.mxLoadResources;
(window as any)["mxLoadStylesheets"] = factoryOption.mxLoadStylesheets;
(window as any)["mxForceIncludes"] = false; // 当通过commonjs加载时为false, 否则会向页面加载script
(window as any)["mxResourceExtension"] = ".txt";

const mxgraph = factory({});

const MxCell = mxgraph.mxCell
const MxConstants = mxgraph.mxConstants
const MxEvent = mxgraph.mxEvent
const MxGraph = mxgraph.mxGraph

const MxRubberBand = mxgraph.mxRubberband

const MxUtils = mxgraph.mxUtils
const MxCodec = mxgraph.mxCodec
const MxGeometry = mxgraph.mxGeometry
const MxEditor = mxgraph.mxEditor
const MxGraphHandler = mxgraph.mxGraphHandler
const MxRectangleShape = mxgraph.mxRectangleShape
const MxCellTracker = mxgraph.mxCellTracker
const MxClient = mxgraph.mxClient
const MxPerimeter = mxgraph.mxPerimeter
const MxEventObject = mxgraph.mxEventObject
const ActiveXObject = mxgraph.activeXObject


MxRubberBand.prototype.defaultOpacity = 30

// decode bug https://github.com/jgraph/mxgraph/issues/49
window['mxGraph'] = mxgraph.mxGraph;
window['mxGraphModel'] = mxgraph.mxGraphModel;
window['mxEditor'] = mxgraph.mxEditor;
window['mxGeometry'] = mxgraph.mxGeometry;
window['mxDefaultKeyHandler'] = mxgraph.mxDefaultKeyHandler;
window['mxDefaultPopupMenu'] = mxgraph.mxDefaultPopupMenu;
window['mxStylesheet'] = mxgraph.mxStylesheet;
window['mxDefaultToolbar'] = mxgraph.mxDefaultToolbar;
// window['mxKeyHandler'] = mxgraph.mxKeyHandler;

export {
  mxgraph,
  MxEvent,
  MxGraph,
  MxEditor,
  MxUtils,
  MxGraphHandler,
  MxConstants,
  MxCodec,
  MxRectangleShape,
  MxCellTracker,
  MxClient,
  MxPerimeter,
  MxEventObject,
  MxGeometry,
  MxCell,
  ActiveXObject
}
